import {expect} from "chai";
import { Vec3 } from "../src/Vec3";
import { Mat3 } from "../src/Mat3";
import { Mat4 } from "../src/Mat4";
describe("Vec3", function () {
    before(function() {
        console.log("开始自动化测试Vec3...");
    });

    after(function() {
        console.log("结束...");
    });
    beforeEach(function() {
    });

    afterEach(function() {
    });

    it('#constructor', function () {
        let vec=new Vec3();
        expect(vec.equal([0,0,0])).to.equal(true);
    });
    it('#x', function () {
        let vec=new Vec3([2,3,0]);
        expect(vec.x).to.equal(2);
    });
    it('#y', function () {
        let vec=new Vec3([2,3,0]);
        expect(vec.y).to.equal(3);
    });
    it('#z', function () {
        let vec=new Vec3([2,3,0]);
        expect(vec.z).to.equal(0);
    });
    it('#toString', function () {
        let vec=new Vec3([2,3,0]);
        expect(vec.toString()).to.equal("Vec3(2,3,0)");
    });
    it('#copy', function () {
        let vec=new Vec3([3,4,0]);
        let o=new Vec3([4,5,6]);
        vec.copy(o)
        expect(vec.toString()).to.equal("Vec3(4,5,6)");
    });
    it('#clone', function () {
        let vec=new Vec3([3,4,0]);
        let vec2=vec.clone();
        expect(vec2.equal(vec)).to.equal(true);
    });
    it('#add', function () {
        let vec=new Vec3([3,4,5]);
        vec.add([1,1,1])
        expect(vec.toString()).to.equal("Vec3(4,5,6)");
    });
    it('#sub', function () {
        let vec=new Vec3([3,4,5]);
        vec.sub([1,1,1])
        expect(vec.toString()).to.equal("Vec3(2,3,4)");
    });
    it('#multiply', function () {
        let vec=new Vec3([3,4,5]);
        vec.multiply([2,3,4])
        expect(vec.toString()).to.equal("Vec3(6,12,20)");
    });
    it('#div', function () {
        let vec=new Vec3([3,4,5]);
        vec.div([3,2,1])
        expect(vec.toString()).to.equal("Vec3(1,2,5)");
    });
    it('#scale', function () {
        let vec=new Vec3([3,4,5]);
        vec.scale(2)
        expect(vec.toString()).to.equal("Vec3(6,8,10)");
    });
    
    it('#negate', function () {
        let vec=new Vec3([3,4,5]);
        vec.negate();
        expect(vec.toString()).to.equal("Vec3(-3,-4,-5)");
    });
    it('#length', function () {
        let vec=new Vec3([3,4,0]);
        expect(vec.length()).to.equal(5);
    });
    it('#distance', function () {
        let vec=new Vec3([4,5,1]);
        expect(vec.distance([1,1,1])).to.equal(5);
    });
    it('#lerp', function () {
        let vec=new Vec3([0,2,4]);
        vec.lerp(0.5);
        expect(vec.toString()).to.equal("Vec3(0,1,2)");
    });
    it('#inverse', function () {
        let vec=new Vec3([2,2,2]);
        vec.inverse();
        expect(vec.toString()).to.equal("Vec3(0.5,0.5,0.5)");
    });
    it('#abs', function () {
        let vec=new Vec3([-2,2,-1]);
        vec.abs();
        expect(vec.toString()).to.equal("Vec3(2,2,1)");
    });
    it('#rotateX', function () {
        let vec=new Vec3([0,1,0]);
        vec.rotateX(Math.PI/2);
        expect(vec.equal([0,0,1])).to.equal(true);
    });
    it('#rotateX1', function () {
        let vecF=new Vec3([0,1,0]);
        vecF.rotateX(Math.PI);
        let vecE=new Vec3([0,1,0]);
        vecE.rotateX(Math.PI);
        vecE.add(vecF);
        expect(vecE.equal([0,-2,0])).to.equal(true);
    });
    it('#rotateY', function () {
        let vec=new Vec3([1,0,0]);
        vec.rotateY(Math.PI/2);
        expect(vec.equal([0,0,-1])).to.equal(true);
    });
    it('#rotateZ', function () {
        let vec=new Vec3([1,0,0]);
        vec.rotateZ(Math.PI/2);
        expect(vec.equal([0,1,0])).to.equal(true);
    });
    it('#angle', function () {
        let vec=new Vec3([1,0,0]);
        let angle=vec.angle([0,1,0]);
        expect(angle).to.be.equal(Math.PI/2);
    });

    it('#dot', function () {
        let vec=new Vec3([1,1,1]);
        expect(vec.dot([2,2,2])).to.equal(6);
    });
    it('#cross', function () {
        let vec=new Vec3([1,0,0]);
        expect(vec.cross([0,1,0]).toString()).to.equal("Vec3(0,0,1)");
    });
    it('#transformMat3', function () {
        let vec=new Vec3([1,0,0]);
        let mat=new Mat3();
        mat.fromRotation(Math.PI/2);
        vec.transformMat3(mat);
        expect(vec.equal([0,1,0])).to.equal(true);
    });
    it('#transformMat4', function () {
        let vec=new Vec3([1,0,0]);
        let mat=new Mat4();
        mat.fromRotation(Math.PI/2,[0,0,1]);
        vec.transformMat4(mat);
        expect(vec.equal([0,1,0])).to.equal(true);
    });
    it('#normalize', function () {
        let vec=new Vec3([1,1,1]);
        vec.normalize();
        expect(vec[0]).to.equal(1/Math.sqrt(3));
    });
    
})